


(function(Global /*, context */) {

    function SetupTooltips(panel) {

        panel.SetPanelEvent("onmouseover", function () {
            // $.Msg(abilityImgELE)
            $.DispatchEvent('DOTAShowAbilityTooltip',panel,panel.abilityname );
        })
        panel.SetPanelEvent("onmouseout",  function (){
            $.DispatchEvent('DOTAHideAbilityTooltip');
        })
    }

    function SetItemData(data) {
        $.Msg(data)
        $("#Kills").text=data.kills;
        $("#Deaths").text=data.deaths;
        $("#PlayerName").text=data.playerName;
        $("#HeroIcon").heroname=data.heroName;
        $("#Ranking").text=$.GetContextPanel().index;
        $("#RankLogo").SetImage("s2r://panorama/images/rank_tier_icons/rank"+data.grade+"_psd.vtex");
        $("#RankGradeName").text=$.Localize("#DOTARankTierName"+data.grade);

        if(data.modifyRank){
            if(data.modifyRank>=0){
                $("#Rank").text=data.rank+"(<font color='#32cd32'>+"+data.modifyRank+"</font>)";
            }
            else{
                $("#Rank").text=data.rank+"(<font color='#8b0000'>"+data.modifyRank+"</font>)";
            }
        }
        else {
            $("#Rank").text=data.rank
        }

        for(var i=1;i<= Global.GameConfig.abilitiesSlotCount;i++){
            var abilityImgELE=  $("#PlayerAbilitiesContainer").FindChildTraverse("AbilityImg"+i)
            // $.Msg(abilityImgELE)
            if(abilityImgELE===null){
                var rowId="RowContainer"+ Math.floor((i-1)/(Global.GameConfig.abilitiesSlotCount/2));
                var rowContainer=$("#PlayerAbilitiesContainer").FindChildTraverse( rowId)
                // $.Msg(rowId)
                if(rowContainer===null){
                    $("#PlayerAbilitiesContainer").GetChild(0).BCreateChildren("<Panel id='"+rowId+"' class='RowContainer' />");
                    rowContainer=$("#PlayerAbilitiesContainer").FindChildTraverse(rowId)
                }
                var id="AbilityImg"+i;
                rowContainer.BCreateChildren("<DOTAAbilityImage id='"+id+"' />");
                abilityImgELE=$("#PlayerAbilitiesContainer").FindChildTraverse("AbilityImg"+i)
            }
            abilityImgELE.abilityname=data.abilityNames[i]
            SetupTooltips(abilityImgELE)
        }

        switch (Number($.GetContextPanel().index)){
            case 1:
                $("#Ranking").style.color="#ff7443";
                break;
            case 2:
                $("#Ranking").style.color="#ff9441";
                break;
            case 3:
                $("#Ranking").style.color="#ffe16c";
                break;
            default:
                $("#Ranking").style.color=null;
                break;
        }
    }

    $.GetContextPanel().SetItemData = SetItemData;

})(GameUI.CustomUIConfig(), this);